using Unity.Burst;
using Unity.Entities;

partial struct ShootlightSystem : ISystem
{
    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        EntityCommandBuffer entityCommandBuffer =
       SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>().CreateCommandBuffer(state.WorldUnmanaged);

        foreach ((RefRW<ShootLight> shootLight, Entity entity) in SystemAPI.Query<RefRW<ShootLight>>().WithEntityAccess())
        {
            shootLight.ValueRW.time -= SystemAPI.Time.DeltaTime;
            if (shootLight.ValueRW.time < 0)
            {
                entityCommandBuffer.DestroyEntity(entity);
            }
        }
    }
}
